package com.leyou.sh.search.listener;

import com.leyou.sh.search.service.IndexService;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author balisong_fcs
 * @date 2021/1/8 20:44
 * @desc
 */
@Component
public class ItemListener {
    @Autowired
    private IndexService indexService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "item.up.queue", declare = "true"),
            exchange = @Exchange(name = "jhj", type = "topic"),
            key = "item.up"
    ))
    public void itemUp(Long id) {
        this.indexService.createIndexById(id);
    }
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "item.down.queue", declare = "true"),
            exchange = @Exchange(name = "jhj", type = "topic"),
            key = "item.down"
    ))
    public void itemDown(Long id) {
        this.indexService.deleteById(id);
    }
}
